package com.grass.appointment.model;

import android.content.Context;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.google.gson.Gson;
import com.grass.appointment.bean.AttentionBean;
import com.grass.appointment.bean.DynamicListBean;
import com.grass.appointment.bean.ReqDynamicLike;

public class DynamicModel extends ViewModel {
    private MutableLiveData<BaseRes<AttentionBean>> attention;
    private MutableLiveData<BaseRes<DynamicListBean>> data;
    private MutableLiveData<BaseRes<String>> like;
    private MutableLiveData<BaseRes<DynamicListBean>> typeDynamicData;
    private MutableLiveData<BaseRes<AttentionBean>> unAttention;
    private MutableLiveData<BaseRes<String>> unLike;

    public MutableLiveData<BaseRes<DynamicListBean>> getTypeDynamicData() {
        if (this.typeDynamicData == null) {
            this.typeDynamicData = new MutableLiveData<>();
        }
        return this.typeDynamicData;
    }

    public MutableLiveData<BaseRes<AttentionBean>> attention() {
        if (this.attention == null) {
            this.attention = new MutableLiveData<>();
        }
        return this.attention;
    }

    public MutableLiveData<BaseRes<AttentionBean>> unAttention() {
        if (this.unAttention == null) {
            this.unAttention = new MutableLiveData<>();
        }
        return this.unAttention;
    }

    public MutableLiveData<BaseRes<DynamicListBean>> data() {
        if (this.data == null) {
            this.data = new MutableLiveData<>();
        }
        return this.data;
    }

    public MutableLiveData<BaseRes<String>> like() {
        if (this.like == null) {
            this.like = new MutableLiveData<>();
        }
        return this.like;
    }

    public MutableLiveData<BaseRes<String>> unLike() {
        if (this.unLike == null) {
            this.unLike = new MutableLiveData<>();
        }
        return this.unLike;
    }

    public void getInfo(int i, int i2) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().dynamicList(i, i2), new HttpCallback<BaseRes<DynamicListBean>>("dynamicList") {
            /* class com.grass.appointment.model.DynamicModel.C28371 */

            public void onLvSuccess(BaseRes<DynamicListBean> baseRes) {
                DynamicModel.this.data.setValue(baseRes);
            }
        });
    }

    public void likeDynamic(int i, Context context) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().likeDynamic(), new Gson().toJson(new ReqDynamicLike(i)), new HttpCallback<BaseRes<String>>("likeDynamic", context) {
            /* class com.grass.appointment.model.DynamicModel.C28382 */

            public void onLvSuccess(BaseRes<String> baseRes) {
                DynamicModel.this.like.setValue(baseRes);
            }
        });
    }

    public void likeUnDynamic(int i, Context context) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().likeUnDynamic(), new Gson().toJson(new ReqDynamicLike(i)), new HttpCallback<BaseRes<String>>("likeUnDynamic", context) {
            /* class com.grass.appointment.model.DynamicModel.C28393 */

            public void onLvSuccess(BaseRes<String> baseRes) {
                DynamicModel.this.unLike.setValue(baseRes);
            }
        });
    }

    public void followUser(int i, Context context) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().followUser(), JsonParams.build().add("beenUserId", Integer.valueOf(i)).commit(), new HttpCallback<BaseRes<AttentionBean>>("followUser", context) {
            /* class com.grass.appointment.model.DynamicModel.C28404 */

            public void onLvSuccess(BaseRes<AttentionBean> baseRes) {
                DynamicModel.this.attention.setValue(baseRes);
            }
        });
    }

    public void cancelFollow(int i, Context context) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().cancelFollowUser(), JsonParams.build().add("beenUserId", Integer.valueOf(i)).commit(), new HttpCallback<BaseRes<AttentionBean>>("cancelFollow", context) {
            /* class com.grass.appointment.model.DynamicModel.C28415 */

            public void onLvSuccess(BaseRes<AttentionBean> baseRes) {
                DynamicModel.this.unAttention.setValue(baseRes);
            }
        });
    }

    public void setTypeDynamicData(int i, int i2, int i3) {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().newDynamicList(i, i2, i3), new HttpCallback<BaseRes<DynamicListBean>>("newDynamicList") {
            /* class com.grass.appointment.model.DynamicModel.C28426 */

            public void onLvSuccess(BaseRes<DynamicListBean> baseRes) {
                DynamicModel.this.typeDynamicData.setValue(baseRes);
            }
        });
    }

    public void cancelHttp() {
        HttpUtils.getInsatance().cancelTag("dynamicList");
        HttpUtils.getInsatance().cancelTag("likeDynamic");
        HttpUtils.getInsatance().cancelTag("likeUnDynamic");
        HttpUtils.getInsatance().cancelTag("cancelFollow");
        HttpUtils.getInsatance().cancelTag("followUser");
        HttpUtils.getInsatance().cancelTag("newDynamicList");
    }
}
